package com.movitech.mobile.ddzy.modules.service;

import cn.hutool.core.collection.CollUtil;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 金源流程模板管理
 *
 * @author
 * @version 1.0.0
 * @description 金源流程模板管理
 * @createTime 2024/05/15
 */
public class CgrBpmTemplateUtil {

    enum FlowKindEnum {
        SupplierApprovale("1", "供方入库审批"),
        purchaseSolution("2", "采购方案审批"),
        purchaseDoc("3", "招标文件审批"),
        purchaseCalibrationBid("4", "定标审批");

        private String code;
        private String text;

        FlowKindEnum(String code, String text) {
            this.code = code;
            this.text = text;
        }
    }

    /**
     * 项目分类
     */
    enum ProjectKindEnum {
        HeavyAssets("1", "重资产"),
        LightAssets("2", "轻资产"),
        HuaNanArea("3", "华南区域"),
        Tyzk("4", "筑科本部"),
        NewModel("5", "新模型项目");

        private String code;
        private String text;

        ProjectKindEnum(String code, String text) {
            this.code = code;
            this.text = text;
        }
    }

    static class FlowTemplate {
        //流程大类
        FlowKindEnum flowKind;

        //流程小分类
        ProjectKindEnum projectKind;

        //流程名称
        String name;

        //流程编码
        String code;

        public FlowTemplate(FlowKindEnum flowKind, ProjectKindEnum projectKind, String code, String name) {
            this.flowKind = flowKind;
            this.projectKind = projectKind;
            this.name = name;
            this.code = code;


        }
    }

    /**
     * 供方入库
     */
    private static List<FlowTemplate> flowTemplates = new ArrayList();

    private static Map<String, ProjectKindEnum> projectKindConfig = new HashMap<>();

    private static void config() {
        //供方入库
        flowTemplates.add(new FlowTemplate(FlowKindEnum.SupplierApprovale, ProjectKindEnum.HeavyAssets, "DD_CG_01_", "重资产代建项目-供方入库审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.SupplierApprovale, ProjectKindEnum.LightAssets, "DD_CG_02_", "华南区域-供方入库审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.SupplierApprovale, ProjectKindEnum.HuaNanArea, "DD_CG_03_", "筑科本部-供方入库审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.SupplierApprovale, ProjectKindEnum.Tyzk, "DD_CG_04_", "轻资产代建-供方入库审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.SupplierApprovale, ProjectKindEnum.NewModel, "DD_CG_23_", "新模型项目-供方入库审批单"));
        //采购方案
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseSolution, ProjectKindEnum.HeavyAssets, "DD_CG_05_", "重资产代建项目-采购方案审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseSolution, ProjectKindEnum.HuaNanArea, "DD_CG_06_", "筑科本部-采购方案审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseSolution, ProjectKindEnum.LightAssets, "DD_CG_07_", "华南区域-采购方案审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseSolution, ProjectKindEnum.NewModel, "DD_CG_24_", "新模型项目-采购方案审批单"));
        //招标文件
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseDoc, ProjectKindEnum.HeavyAssets, "DD_CG_08_", "重资产代建项目-招标文件审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseDoc, ProjectKindEnum.HuaNanArea, "DD_CG_09_", "筑科本部-招标文件审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseDoc, ProjectKindEnum.LightAssets, "DD_CG_10_", "华南区域-招标文件审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseDoc, ProjectKindEnum.NewModel, "DD_CG_25_", "新模型项目-招标文件审批单"));
        //定标审批
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseCalibrationBid, ProjectKindEnum.HeavyAssets, "DD_CG_11_", "重资产代建项目-定标审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseCalibrationBid, ProjectKindEnum.HuaNanArea, "DD_CG_12_", "筑科本部-定标审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseCalibrationBid, ProjectKindEnum.LightAssets, "DD_CG_13_", "华南区域-定标审批单"));
        flowTemplates.add(new FlowTemplate(FlowKindEnum.purchaseCalibrationBid, ProjectKindEnum.NewModel, "DD_CG_26_", "新模型项目-定标审批单"));

        //项目类型配置
        //TYZK-ZT01	世纪金源·梧桐印象 - 重
        //TYZK-ZT10	黄山·域见国际旅游度假区 - 重
        //102J00I00I03	学府天宸项目 - 重
        //TYZK-ZT05	金源·学府天宸 - 重
        //TYZK-DJ03	清远春江悦茗 - 重
        //TYZK-ZT02	世纪金源·紫檀南长里 - 重
        //TYZK-ZT03	苏州太湖新城项目 - 重
        //102L00X02005006	深圳沙井项目 - 重

        //TYZK-ZT09	广州天河源筑项目 - 华南

        //TYZK-DJ02	贵州文化广场（河滨剧场） 棚户区改造项目 - 轻
        //102L00F0100788	无锡惠山古镇项目（DE） - 轻
        //102L00F0100788
        //TYZK-ZT04    国京-域见未来 - 轻
        //TYZK20250508    沙井项目（最新）

        //重资产
        projectKindConfig.put("TYZK-ZT01", ProjectKindEnum.HeavyAssets);
        projectKindConfig.put("TYZK-ZT10", ProjectKindEnum.HeavyAssets);
        projectKindConfig.put("102J00I00I03", ProjectKindEnum.HeavyAssets);
        projectKindConfig.put("TYZK-ZT05", ProjectKindEnum.HeavyAssets);
        projectKindConfig.put("TYZK-DJ03", ProjectKindEnum.HeavyAssets);
        projectKindConfig.put("TYZK-ZT02", ProjectKindEnum.HeavyAssets);
        projectKindConfig.put("TYZK-ZT03", ProjectKindEnum.HeavyAssets);
        projectKindConfig.put("TYZK-ZT04", ProjectKindEnum.HeavyAssets);
        projectKindConfig.put("102L00X02005006", ProjectKindEnum.HeavyAssets);
        //华南
        projectKindConfig.put("TYZK-ZT09", ProjectKindEnum.HuaNanArea);
        //轻资产
        projectKindConfig.put("TYZK-DJ02", ProjectKindEnum.LightAssets);
        projectKindConfig.put("102L00F0100788", ProjectKindEnum.LightAssets);
        projectKindConfig.put("TYZK20250508", ProjectKindEnum.NewModel);
    }

    public static FlowTemplate getFlowTemplate(FlowKindEnum flowKind, String projectCode) {
        ProjectKindEnum projectKindEnum = projectKindConfig.get(projectCode);
        if (null == projectKindEnum) {
            throw new RuntimeException(String.format("【%s】项目没有配置项目类型，请联系系统管理员",projectCode));
        }

        List<FlowTemplate> filterFlowTemplate = flowTemplates.stream()
                .filter(item -> (Objects.equals(item.flowKind.code, flowKind.code) && Objects.equals(item.projectKind.code, projectKindEnum.code)))
                .collect(Collectors.toList());
        if (CollUtil.isEmpty(filterFlowTemplate)) {
            throw new RuntimeException(String.format("未获取到项目【%s】的流程模板配置信息，请联系系统管理员",projectCode));
        }
        return filterFlowTemplate.get(0);
    }
    public static FlowTemplate getStorageApprovalFlowTemplate( String projectKind) {

        List<FlowTemplate> filterFlowTemplate = flowTemplates.stream()
                .filter(item -> (Objects.equals(item.flowKind.code, FlowKindEnum.SupplierApprovale.code) && Objects.equals(item.projectKind.code, projectKind)))
                .collect(Collectors.toList());
        if (CollUtil.isEmpty(filterFlowTemplate)) {
            throw new RuntimeException(String.format("获取流程模板异常，请联系系统管理员",projectKind));
        }
        return filterFlowTemplate.get(0);
    }


    static {

        config();

    }
}
